<?php
include 'includes/application_top.inc';
include 'includes/paginate.php';
include 'auth.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Easy Living - Responsive Real Estate Template">
<meta name="keywords" content="Themes, real estate, responsive, themeforest, Templates">
<meta name="author" content="Rype Pixel [Chris Gipple]">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome  Short Url Creation</title>
<!-- html5 support in IE8 and later -->
<script src="../../html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<!-- CSS file links -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/styles.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/responsive.css" rel="stylesheet" type="text/css" media="all" />

<script>
    function validateForm()
    {
        var url = document.getElementById("urlIn").value;
        if(url == '')
        {
            alert("Please enter URL");
            return false;
        }
    }
</script>
</head>
<body>
<!-- Start Header -->
<?php include 'includes/header.php';?>
<!-- End Header -->
<!-- start subheader -->
<p>&nbsp;</p>
<!-- start recent properties -->
<section class="properties">
    <div class="container">
    	<?php include 'includes/left.php';?>
    
        <div class="row">
            <div class="col-sm-6">
                <div class="propertyItem">
                	<!--  onsubmit="validate();"-->
                	<?php  
                	
                		  $user_id = $_SESSION['u_id'];
				$RefAuthid = 3;
				$RefAuthid1 = 4;
				$RefAuthid2 = 1;
				$authEdit  = authentication($RefAuthid,$user_id); 
				$authDelete  = authentication($RefAuthid1,$user_id); 
				$authADD  = authentication($RefAuthid2,$user_id);
                	   if(@$_REQUEST['ac']!="Edit" && $authADD!=1)
					   {
					   	echo '<p align="center"><br><br><br><br><b>You have been denied to access</b><br><br><br><br></p>';
					   }
                	   if(@$_REQUEST['ac']=="Edit" && $authEdit!=1)
					   {
					   	echo '<p align="center"><br><br><br><br><b>You have been denied to access.</b><br><br><br><br></p>';
					   }
					                   	
                
				/*if($authEdit==1 && $authDelete==1)
				{ */ ?>
					
					
                	<form name="form" method="post" id="form" action="action.php">
                		<table border="0" class="propertyDetails">
				
                <?php
               		 
                $pagesUrl = "tpages=".@$_REQUEST['tpages']."&page=".@$_REQUEST['page'];
                
                if(@$_REQUEST['ac']=="Edit" && $authEdit==1)
				{
					echo '<tr><td colspan="2"><h1>Edit Full URL</h1></td></tr> 			
				<tr><td colspan="2">&nbsp;</td></tr> 
				<input type="hidden" name="EditSurl" id="secEditSurl" value="EDITSHURL" />';
					echo '<input type="hidden" name="id" id="id" value="'.$_REQUEST['id'].'" />';
					
					echo '<input type="hidden" name="tpages" id="id" value="'.$_REQUEST['tpages'].'" />';
					echo '<input type="hidden" name="page" id="id" value="'.$_REQUEST['page'].'" />';									
				}else if($authADD ==1 && @$_REQUEST['ac'] != "Edit") 
				{
				echo '<tr><td colspan="2"><h1>Insert Full URL</h1></td></tr> 			
				<tr><td colspan="2">&nbsp;</td></tr>
				<input type="hidden" name="security" id="security" value="SHORTURL"  />';	
				}
                ?>                		
								  	 
				<?php
                if(@$_REQUEST['ac']=="emsg"){ echo '<tr><td colspan="2">url is wrong</td></tr>';}
                 
                if(@$_REQUEST['ac']=="suss"){ echo '<tr><td colspan="2">thankyou for use</td></tr>';}
                 
                if(@$_REQUEST['aced']=="edsuss"){ echo '<tr><td colspan="2">Long url has updated successfully</td></tr>';}
                ?> 
                <?php
                 if(@$_REQUEST['ac']=="Edit" && $authEdit==1 ) {
                 	
					$id = $_REQUEST['id'];
					$sql = "Select * from shorturl where id=$id";
					$query = mysql_query($sql);
					$row = mysql_fetch_array($query);
					$shorturl_code = $row['shorturl_code']; 
                                        $lUrl = $row['long_url'];
                 	?>
		 <tr><td>Short Url</td><td><?php echo ROOTURL. $shorturl_code;?></td></tr>   			
		 <!--<tr><td>Short Url</td><td><input type="text" name="url" id="url" value="<?php echo @$_REQUEST['url']; ?>" style="width: 450px;"  />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>-->     
                 <tr><td>Long Url</td><td><input type="text" name="url" id="url" value="<?php echo $lUrl; ?>" style="width: 450px;"  />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
		  
		  	<input type="hidden" name="status" id="status" value="EDITSHURL">		  	
		   
		<tr align="right"><td>&nbsp;</td><td><input id="submit" type="submit" value="Update Url" name="submit" accesskey="l" />&nbsp;&nbsp;&nbsp;&nbsp;<!--<input type="submit" value="Delete" onclick="redirecttest('<?php echo $id;?>');" />--></td></tr> 		
                <?php
				}else if($authADD ==1 && @$_REQUEST['ac'] != "Edit") 
					{?>
                  <tr><td><input type="text" size="50" name="url" id="urlIn" value="<?php echo @$_REQUEST['url']; ?>" style="width: 450px;"  />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="submit" type="submit" value="Shorten" onclick="return validateForm();" name="submit" accesskey="l" /></td></tr> </form>
					<?php }?>
					</table>
				
					</form>
				 	<?php
				/*}else { echo '<p align="center"><b>You have been denied to access.<br> Need to Edit & Delete permission</b></p>';}*/	?>
					
			 <br><br><br><br>
                </div>
            </div>
        </div><!-- end row -->
    </div><!-- end container -->
</section>
<!-- end recent properties -->
<div class="bottomBar">
    <div class="container">
  <!--      <p>CopyRight @ News Nation</p>-->
    </div>
</div>

<!-- JavaScript file links -->
<script src="js/jquery.js"></script>			<!-- Jquery -->
<script src="js/jquery.validate.js"></script>   <!---Form Validate Plugin ---->
<script src="js/register.jquery.js"></script>   <!-----Validation-------->
<script src="js/bootstrap.min.js"></script>  <!-- bootstrap 3.0 -->
<script src="js/respond.js"></script>


	 

<script type="text/javascript">
    function validate() {
        var url = document.getElementById("url").value;
        var pattern = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
        if (pattern.test(url)) {
            alert("Url is valid");
            return true;
        }else
        {
        	alert("Url is not valid!");
            return false;

        } 
            
    }
</script>
<script type="text/javascript">
	function redirecttest (argument) {
	  <!--
   var retVal = confirm("Do you want to delete ?");
   if( retVal == true ){
//      alert("User wants to continue!");
      window.location="action.php?URE=DELETE&<?php echo $pagesUrl;?>&id="+argument;
	  return true;
   }else{
    //  alert("User does not want to continue!");
	  return false;
   }
//-->
	}

</script>
</body>
</html>